<html>
<head><meta charset="utf-8"><title>CppCon 2019: JF Bastien “Deprecating volatile” · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html">CppCon 2019: JF Bastien “Deprecating volatile”</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178616428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178616428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178616428">(Oct 21 2019 at 00:09)</a>:</h4>
<p>To all the folks in UCG who have been working with where Volatile should go in Rust, here's a talk released yesterday about where Volatile has been and (for C++) where it might be going. Could be helpful for tackling volatile in Rust as well.<br>
<a href="https://www.youtube.com/watch?v=KJW_DLaVXIY" target="_blank" title="https://www.youtube.com/watch?v=KJW_DLaVXIY">https://www.youtube.com/watch?v=KJW_DLaVXIY</a></p>
<div class="youtube-video message_inline_image"><a data-id="KJW_DLaVXIY" href="https://www.youtube.com/watch?v=KJW_DLaVXIY" target="_blank" title="https://www.youtube.com/watch?v=KJW_DLaVXIY"><img src="https://i.ytimg.com/vi/KJW_DLaVXIY/default.jpg"></a></div>



<a name="178674349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178674349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178674349">(Oct 21 2019 at 16:51)</a>:</h4>
<p>thanks; I know they have some ongoing work there but it's good to get an update</p>



<a name="178674424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178674424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178674424">(Oct 21 2019 at 16:52)</a>:</h4>
<p>last time I checked it wasnt very Rust-relevant; IIRC they were moving more towards volatile <em>accesses</em> as opposed to volatile <em>objects</em> which is what we already do anyway... or am I entirely misremembering?</p>



<a name="178684896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178684896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178684896">(Oct 21 2019 at 18:40)</a>:</h4>
<p>Yeah we already do what they're trying to move towards in the next few years.</p>
<p>I'd say the biggest deal there is that volatile access can tear, and they <em>don't</em> plan to fix that for normal volatile, because the hardware itself doesn't even always give you that assurance.</p>



<a name="178691375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178691375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178691375">(Oct 21 2019 at 19:53)</a>:</h4>
<p>yeah... though it still seems useful to guarantee that we dont tear the instruction. that lets the user reason on the hardware level.</p>



<a name="178691422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178691422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178691422">(Oct 21 2019 at 19:53)</a>:</h4>
<p>it is somewhat disappointing that with their volatile load/store methods they are copying Rust's design but not citing it as prior work :/</p>



<a name="178693748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178693748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hadrien Grasland <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178693748">(Oct 21 2019 at 20:14)</a>:</h4>
<p>Isn't Rust itself copying what LLVM does here ?</p>



<a name="178694313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178694313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178694313">(Oct 21 2019 at 20:20)</a>:</h4>
<p>possible? not sure what the API was inspired from</p>



<a name="178694326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178694326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178694326">(Oct 21 2019 at 20:20)</a>:</h4>
<p>however it does make a difference whether one designs an IR or a surface language</p>



<a name="178694360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178694360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178694360">(Oct 21 2019 at 20:21)</a>:</h4>
<p>and Rust as a surface language has some experience now with volatile-access-methods, which is not something where having it in LLVM helps</p>



<a name="178711823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178711823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178711823">(Oct 22 2019 at 00:16)</a>:</h4>
<p>yeah Rust and the C++ plan are both copying LLVM's notion of how things work.</p>



<a name="178748219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748219">(Oct 22 2019 at 12:02)</a>:</h4>
<p>That talk is mostly C++ fixing C++-specific weirdness</p>



<a name="178748246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748246">(Oct 22 2019 at 12:03)</a>:</h4>
<p>Once they do that, they might get to the point were the only weirdness remaining is the same one Rust needs to deal with</p>



<a name="178748266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748266">(Oct 22 2019 at 12:03)</a>:</h4>
<p>but until then, they just have lower hanging fruit to fix</p>



<a name="178748289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748289">(Oct 22 2019 at 12:03)</a>:</h4>
<p>they might be proposing moving to a model were volatile and atomics aren't types, but types of memory accesses instead</p>



<a name="178748295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748295">(Oct 22 2019 at 12:03)</a>:</h4>
<p>apparently that's what the Linux kernel does</p>



<a name="178748350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748350">(Oct 22 2019 at 12:04)</a>:</h4>
<p>also, they use the term atomic to mean, among other things "not tearing"</p>



<a name="178748402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748402">(Oct 22 2019 at 12:05)</a>:</h4>
<p>(or maybe even "at least not tearing", whether all atomics will synchronize appears to be disputed but the talk does not go into it)</p>



<a name="178748552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748552">(Oct 22 2019 at 12:07)</a>:</h4>
<p>An interesting example they show is the following:</p>
<div class="codehilite"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="n">FOO</span>: <span class="kt">i32</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="o">&amp;</span><span class="n">FOO</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">_</span><span class="p">).</span><span class="n">read_volatile</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>they don't propose being able to optimize <code>foo</code> into <code>fn foo() {}</code> but they ask the question: "what does that do?"</p>



<a name="178748623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178748623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178748623">(Oct 22 2019 at 12:08)</a>:</h4>
<p>e.g. even if that does MMIO, is there a target where reading the memory has some interesting side-effects or can the read be elided ?</p>



<a name="178772200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178772200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178772200">(Oct 22 2019 at 16:30)</a>:</h4>
<p>there's definitely targets where a read has a side effect of its own</p>



<a name="178772237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178772237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178772237">(Oct 22 2019 at 16:30)</a>:</h4>
<p>the only one that comes to mind offhand is the NES, but i bet we could find others</p>



<a name="178773899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon%202019%3A%20JF%20Bastien%20%E2%80%9CDeprecating%20volatile%E2%80%9D/near/178773899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hadrien Grasland <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/CppCon.202019.3A.20JF.20Bastien.20.E2.80.9CDeprecating.20volatile.E2.80.9D.html#178773899">(Oct 22 2019 at 16:53)</a>:</h4>
<p>On every platform that has an MMU, a read can cause a page fault, which in turn can have arbitrary software-defined side-effects.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>